//===============================================================================
// Microsoft patterns & practices
// Web Client Software Factory
//-------------------------------------------------------------------------------
// Copyright (C) Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//-------------------------------------------------------------------------------
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================
using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Configuration;
using System.IO;
using WCSFContrib.PageFlow.Xml.Configuration;
using WCSFContrib.PageFlow;
using WCSFContrib.PageFlow.Xml.Services;
using WCSFContrib.PageFlow.Xml.Tests.Mocks;

namespace WCSFContrib.PageFlow.Xml.Tests.Configuration
{
    /// <summary>
    /// Summary description for XmlPageFlowConfigurationFixture
    /// </summary>
    [TestClass]
    public class XmlPageFlowConfigurationFixture
    {
        private IDictionary<string, NavigationGraph> _navigationGraphs;
        private readonly string ShoppingNavigationGraphTypeName = typeof(MockUnconstrainedPageFlow).AssemblyQualifiedName;
        private readonly string CheckoutNavigationGraphTypeName = typeof(MockConstrainedPageFlow).AssemblyQualifiedName;

        public XmlPageFlowConfigurationFixture()
        {
    
        }

        [TestInitialize]
        public void SetUp()
        {
            AppDomain.CurrentDomain.SetData("APPBASE", Environment.CurrentDirectory);
            _navigationGraphs = new WebConfigStore().GetXmlPageFlowNavigationGraphs();
        }

        [TestMethod]
        [DeploymentItem("Web.config")]
        public void GetNavigationGraphs()
        {
            Assert.AreEqual(2, _navigationGraphs.Count);
            Assert.AreEqual("shopping", _navigationGraphs[ShoppingNavigationGraphTypeName].Name);
            Assert.AreEqual("checkout", _navigationGraphs[CheckoutNavigationGraphTypeName].Name);
        }

        [TestMethod]
        [DeploymentItem("Web.config")]
        public void GetBackButtonValue()
        {
            Assert.IsTrue(_navigationGraphs[ShoppingNavigationGraphTypeName].Constrained);
        }

        [TestMethod]
        [DeploymentItem("Web.config")]
        public void GetViewNodes()
        {
            Assert.AreEqual(2, _navigationGraphs[ShoppingNavigationGraphTypeName].Views.Count);
            Assert.AreEqual("cart", _navigationGraphs[ShoppingNavigationGraphTypeName].Views[0].Name);
            Assert.AreEqual("cart.aspx", _navigationGraphs[ShoppingNavigationGraphTypeName].Views[0].Url);
        }

        [TestMethod]
        [DeploymentItem("Web.config")]
        public void GetNavigationGraphNodes()
        {
            Assert.AreEqual("shopping", _navigationGraphs[ShoppingNavigationGraphTypeName].Name);
            Assert.AreEqual(typeof(InMemoryXmlPageFlowInstanceStore), _navigationGraphs[ShoppingNavigationGraphTypeName].InstanceStore.GetType());
            Assert.AreEqual(typeof(MockUnconstrainedPageFlow), _navigationGraphs[ShoppingNavigationGraphTypeName].PageFlowType);
            Assert.AreEqual("cart", _navigationGraphs[ShoppingNavigationGraphTypeName].StartView.Name);
            Assert.AreEqual("cart.aspx", _navigationGraphs[ShoppingNavigationGraphTypeName].StartView.Url);
            Assert.AreEqual(AbandonBehavior.Prevent, _navigationGraphs[ShoppingNavigationGraphTypeName].Abandonable);
            Assert.AreEqual("NotRunning.aspx", _navigationGraphs[ShoppingNavigationGraphTypeName].NotRunningUrl);
            Assert.AreEqual("Abort.aspx", _navigationGraphs[ShoppingNavigationGraphTypeName].AbortUrl);
        }

        [TestMethod]
        [DeploymentItem("Web.config")]
        public void GetNodeNodes()
        {
            Assert.AreEqual(2, _navigationGraphs[ShoppingNavigationGraphTypeName].Views.Count);
            Assert.AreEqual("cart", _navigationGraphs[ShoppingNavigationGraphTypeName].Views[0].Name);
            Assert.AreEqual("cart.aspx", _navigationGraphs[ShoppingNavigationGraphTypeName].Views[0].Url);
        }

        [TestMethod]
        [DeploymentItem("Web.config")]
        public void GetNavigateToNodes()
        {
            Assert.AreEqual(2, _navigationGraphs[ShoppingNavigationGraphTypeName].Views[0].Transitions.Count);
            Assert.IsTrue(_navigationGraphs[ShoppingNavigationGraphTypeName].Views[0].ContainsTransition("resume"));
            Assert.IsNull(_navigationGraphs[ShoppingNavigationGraphTypeName].Views[0].TryGetTransitionFromTransitionName("resume").Condition);
            Assert.AreEqual("browsecatalog", _navigationGraphs[ShoppingNavigationGraphTypeName].Views[0].TryGetTransitionFromTransitionName("resume").View.Name);
            Assert.AreEqual("browse.aspx", _navigationGraphs[ShoppingNavigationGraphTypeName].Views[0].TryGetTransitionFromTransitionName("resume").View.Url);

            Assert.IsTrue(_navigationGraphs[ShoppingNavigationGraphTypeName].Views[0].ContainsTransition("resume2"));
            Assert.IsNull(_navigationGraphs[ShoppingNavigationGraphTypeName].Views[0].TryGetTransitionFromTransitionName("resume2").View);
            Assert.AreEqual("CheckSomething", _navigationGraphs[ShoppingNavigationGraphTypeName].Views[0].TryGetTransitionFromTransitionName("resume2").Condition);
            Assert.IsNull(_navigationGraphs[ShoppingNavigationGraphTypeName].Views[0].TryGetViewFromTransitionName("resume2"));
        }
    }
}
